package com.zhang.limit;

import com.google.common.util.concurrent.RateLimiter;

import java.util.concurrent.TimeUnit;

/**
 * 平滑型限流
 */
public class SmoothWarmingUpDemo {
    public static void main(String[] args) throws InterruptedException {
        // 预热1秒，凭证5个
        RateLimiter limiter = RateLimiter.create(5, 1000, TimeUnit.MILLISECONDS);
        for (int i = 1; i < 5; i++) {
            System.out.println(limiter.acquire());
        }
        Thread.sleep(1000L);
        for (int i = 1; i < 5; i++) {
            System.out.println(limiter.acquire());
        }
        for (int i = 1; i < 5; i++) {
            System.out.println(limiter.acquire());
        }
    }
}
